home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
Tickle-4.0 (tcl)
/
src
/
Command.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
11KB
|
491 lines
#ifdef MPW3
# pragma segment COMMAND
#endif
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#include "tickle.h"
#include "TGE.h"
#include "tcl.h"
extern int tcl_feedback_output();
/*
** This is where all of the menu commands are parsed out and
** handled. MenuSelection contains the menu ID and the item
** picked in that menu. These two numbers are shorts inside
** a long integer.
*/
do_command(MenuSelection)
long MenuSelection;
{
char name[256];
int refNum, doit;
WindowPtr myWindow;
int theMenu, theitem;
Rect myrect;
extern Boolean cvtNl;
extern Boolean oldArch;
/*
** The menu ID is the "high" short in the long integer.
*/
theMenu = (short)((MenuSelection >> 16) & 0x0000FFFF);
/*
** The menu item picked is the "low" short in the long integer.
*/
theitem = (short)(MenuSelection & 0x0000FFFF);
myWindow = FrontWindow();
/*
** Parse the menu ID and item picked into the appropriate commands.
*/
switch (theMenu) {
case applemenu:
if (theitem == infoitem) {
do_info();
clear_notify_q(NOTIFY_ALL);
}
else {
GetItem(mymenus[0], theitem, name);
refNum = OpenDeskAcc(name);
}
break;
case filemenu:
switch(theitem) {
case page_setup_item:
PageSetUp();
break;
case new_item:
{
Tcl_Interp *interp;
extern WindowPtr MakeTextTGE();
SetRect(&myrect, 10, 50, 410, 250);
myWindow = MakeTextTGE(&myrect, "Untitled", "", 0);
if (myWindow != NULL)
{
T_UNSETSTATE(TGEWPtr->state, T_TCL_STATE);
if ( (menu_modifiers & shiftKey) != 0 && g_interp != NULL )
{
/* GLOBAL */
T_SETSTATE(TGEWPtr->state, T_GLOBAL_TCL_STATE);
interp = g_interp;
}
else
{
/* LOCAL */
T_UNSETSTATE(TGEWPtr->state, T_GLOBAL_TCL_STATE);
interp = Tcl_CreateTickleInterp();
if (interp != NULL)
TickleInitLocalShell(interp, myWindow);
}
TGEWPtr->fobject = (void *)interp;
if (interp != NULL)
{
T_SETSTATE(TGEWPtr->state, T_TCL_STATE);
SetPort(myWindow);
tge_inval_status_box(myWindow);
}
UInitCursor();
}
}
break;
case open_item:
do_tge_file_open(NULL, (menu_modifiers & shiftKey) != 0);
break;
case save_item:
if (myWindow != NULL && WPeek->windowKind == tgeWKind)
wind_parse(myWindow, NULL, wSave);
break;
case save_as_item:
if (myWindow != NULL && WPeek->windowKind == tgeWKind)
wind_parse(myWindow, NULL, wSaveAs);
break;
case print_window_item:
if (myWindow != NULL)
wind_parse(myWindow, NULL, wPrint);
break;
case print_selection_item:
if (myWindow != NULL)
wind_parse(myWindow, NULL, wPrintSelection);
break;
case run_script_item:
run_tcl_script(NULL, tcl_feedback_output);
break;
case new_folder_item:
CreateDirectory();
break;
case open_fb_item:
if (feedback_showing)
HideFeedback();
else
ShowFeedback();
break;
case close_window_item:
if (myWindow != NULL)
wind_parse(myWindow, NULL, wClose);
break;
case pause_op_item:
if (pause_op)
{
pause_op = 0;
SetCursor(*GetCursor(watchCursor));
SetItem(file_menu_hdl, pause_op_item, "\pPause");
}
else
{
pause_op = 1;
InitCursor();
SetItem(file_menu_hdl, pause_op_item, "\pContinue");
}
break;
case cancel_op_item:
pause_op = 0;
cancel_current_op = 1;
SetItem(file_menu_hdl, pause_op_item, "\pPause");
clear_notify_q(NOTIFY_ALL);
break;
case stop_icons_item:
clear_notify_q(NOTIFY_ALL);
break;
case quit_item:
doit = 1;
if (yielding_on)
if (! AskYesNo("Sure you wanna quit?", 0))
doit = 0;
if (doit) {
cancel_current_op = 1;
pause_op = 0;
app_done = true;
clear_notify_q(NOTIFY_ALL);
}
break;
case log_level_item:
if (CheckOption()) {
name[0] = '\0';
if (GetInputLine("Mark String:", name)) {
UUDEBUG(0, "LOGMARK: %s\n", name);
}
}
else {
name[0] = '\0';
sprintf(temp_str, "Current log level = %d. Enter new level:", g_log_level);
if (GetInputLine(temp_str, name)) {
g_log_level = atoi(name);
UUDEBUG(0, "Log level set to %d.\n", g_log_level);
}
}
break;
case log_item:
if (logfile == NULL) {
extern int errno;
Point mypoint;
SFReply myreply;
if (CheckOption()) {
mypoint.h = mypoint.v = 75;
MyPutFile(mypoint, "\pLog File:", "\pLOGFILE", NULL, &myreply);
if (myreply.good) {
SetVol(NULL, myreply.vRefNum);
p2cstr(myreply.fName);
logfile = fopen(myreply.fName, "a");
if (logfile == NULL) {
message_alert("Error #%d opening log file.", errno);
}
else {
SetItem(file_menu_hdl, log_item, "\pEnd Logging");
strcpy(g_log_filename, myreply.fName);
g_log_wdref = myreply.vRefNum;
}
}
}
else {
SetVol(NULL, g_log_wdref);
logfile = fopen(g_log_filename, "a");
if (logfile == NULL) {
message_alert("Error #%d opening log file.", errno);
}
else {
SetItem(file_menu_hdl, log_item, "\pEnd Logging");
}
}
}
else {
fclose(logfile);
FlushVol(NULL, app_vrefnum);
logfile = (FILE *)0;
SetItem(file_menu_hdl, log_item, "\pBegin Logging");
}
break;
}
break;
case editmenu:
if (! SystemEdit(theitem)) {
switch(theitem) {
case cutCmd:
wind_parse(myWindow, NULL, wCut);
break;
case copyCmd:
wind_parse(myWindow, NULL, wCopy);
break;
case pasteCmd:
wind_parse(myWindow, NULL, wPaste);
break;
case undoCmd:
wind_parse(myWindow, NULL, wUndo);
break;
case clearCmd:
wind_parse(myWindow, NULL, wDelete);
break;
case selectAllCmd:
wind_parse(myWindow, NULL, wSelectAll);
break;
case findCmd:
wind_parse(myWindow, NULL, wFind);
break;
case repeatFindCmd:
wind_parse(myWindow, NULL, wRepeatFind);
break;
case replaceCmd:
wind_parse(myWindow, NULL, wReplace);
break;
case repeatReplaceCmd:
wind_parse(myWindow, NULL, wRepeatReplace);
break;
case shiftLeftCmd:
if (WPeek->windowKind == tgeWKind)
tge_left_shift_selection(myWindow, 4/*UNDONE*/);
break;
case shiftRightCmd:
if (WPeek->windowKind == tgeWKind)
tge_right_shift_selection(myWindow, 4/*UNDONE*/);
break;
}
}
break;
case tcl_menu:
scripts_menu_run(theitem);
break;
case ttoolmenu:
clear_notify_q(NOTIFY_ALL);
switch(theitem) {
case f_split_item:
split_file();
break;
case f_join_item:
join_files();
break;
case f_convert_item:
ConvertTextFile();
break;
case f_texttype_item:
FileTypeTEXT();
break;
case f_unixtomac_item:
UnixToMac();
break;
case f_mactounix_item:
MacToUnix();
break;
case f_pctomac_item:
PCToMac();
break;
case f_mactopc_item:
MacToPC();
break;
}
break;
case mtoolmenu:
clear_notify_q(NOTIFY_ALL);
switch(theitem) {
case f_macbinary_item:
DoMacBinary(BINARY_FILE);
break;
case f_unmacbinary_item:
DoMacBinary(MAC_FILE);
break;
case mb_info_item:
SF_mbinfo();
break;
case f_binhex_item:
SFencode_hqx();
break;
case f_unbinhex_item:
SFdecode_hqx();
break;
case f_copyhier_item:
copy_to_floppies();
break;
case f_macinfo_item:
SFFileInfo();
break;
}
break;
case hcsubmenu:
clear_notify_q(NOTIFY_ALL);
switch (theitem) {
case hc_ftype_item:
hfs_set_file_info(0);
break;
case hc_fcreator_item:
hfs_set_file_info(1);
break;
case hc_folderview_item:
set_folder_views();
break;
case hc_file_info_item:
show_file_info();
break;
case hc_folder_info_item:
show_folder_info();
break;
case hc_filefld_info_item:
show_file_and_folder_info();
break;
}
break;
case xcsubmenu:
clear_notify_q(NOTIFY_ALL);
break;
case stoolmenu:
clear_notify_q(NOTIFY_ALL);
switch(theitem) {
case f_stuff_file_item:
StuffItFile();
break;
case f_stuff_mult_item:
StuffItMultiple();
break;
case f_unstuff_item:
UnStuffIt();
break;
}
break;
case utoolmenu:
clear_notify_q(NOTIFY_ALL);
switch(theitem) {
case f_uuencode_item:
SFuuencode();
break;
case f_uudecode_item:
SFuudecode();
break;
case f_decompress_item:
SFdecompress();
break;
case f_compress_item:
SFcompress();
break;
}
break;
case tarmenu:
clear_notify_q(NOTIFY_ALL);
switch(theitem) {
case tar_create_item:
ArCreate();
break;
case tar_extract_item:
Extract();
break;
case tar_list_item:
List();
break;
case tar_about_item:
DoAboutBox();
break;
}
break;
case ptarmenu:
clear_notify_q(NOTIFY_ALL);
switch(theitem) {
case ptar_cnvrt_nl_item:
cvtNl ^= true;
CheckItem(ptar_menu_hdl, ptar_cnvrt_nl_item, cvtNl);
break;
case ptar_old_tar_item:
oldArch ^= true;
CheckItem(ptar_menu_hdl, ptar_old_tar_item, oldArch);
break;
case ptar_blk_size_item:
DoBlockSize();
break;
case ptar_crtr_type_item:
DoCreatorType();
break;
}
break;
case asdmenu:
clear_notify_q(NOTIFY_ALL);
switch (theitem) {
case asd_info_item:
SF_asd_info();
break;
case asd_to_mb_item:
SF_asd_to_mb();
break;
case asd_to_mac_item:
SF_asd_to_Mac();
break;
case mb_to_as_item:
macbinary_to_asingle(0);
break;
case mb_to_ad_item:
macbinary_to_adouble(0);
break;
case mac_to_as_item:
macintosh_to_asingle(0);
break;
case mac_to_ad_item:
macintosh_to_adouble(0);
break;
}
break;
}
/*
** Since many commands can change the
** current working directory, set it back!
*/
TclMac_CWDSetVol();
HiliteMenu(0);
}